package drive.Controller;

import drive.Model.ArticleImage;
import drive.Service.ServiceInterface.ArticleImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/articleImage")
public class ArticleImageController {

    @Autowired
    private ArticleImageService articleImageService;

    @GetMapping()
    public String getAllArticleImages() {
        return articleImageService.findAll();
    }

    @GetMapping("/article/{articleID}")
    public String getArticleImagesByArticleID(@PathVariable("articleID") Integer articleID) {
        return articleImageService.findByArticleID(articleID);
    }

    @GetMapping("/image/{imageID}")
    public String getArticleImagesByImageID(@PathVariable("imageID") Integer imageID) {
        return articleImageService.findByImageID(imageID);
    }

    @PostMapping()
    public String addArticleImage(@RequestBody ArticleImage articleImage) {
        return articleImageService.add(articleImage);
    }

    @DeleteMapping("/{articleID}/{imageID}")
    public String deleteArticleImage(@PathVariable("articleID") Integer articleID, @PathVariable("imageID") Integer imageID) {
        return articleImageService.delete(articleID, imageID);
    }
}